<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <meta name="renderer" content="webkit">
    <title>网站信息</title>  
    <link rel="stylesheet" href="__CSS__/pintuer.css?v={$src_version}">
    <link rel="stylesheet" href="__CSS__/admin.css?v={$src_version}">
    <link rel="stylesheet" href="__CSS__/responsive.css?v={$src_version}">
	  <script src="__JS__/jquery-3.2.1.min.js?v={$src_version}"></script>
    <script src="__JS__/pintuer.js?v={$src_version}"></script>
    <script src="__JS__/jquery.nicescroll.js"></script>
    <script src="__PUBLIC__/layer.js?v={$src_version}"></script>
    <script src="__PUBLIC__/js/ming.js?v={$src_version}"></script>
    <script src="__JS__/ifram_scroll.js?v={$src_version}"></script> 
    <script src="__JS__/plupload.full.min.js?v={$src_version}"></script>
    <script src="__JS__/responsive.js?v={$src_version}"></script>   
</head>
<body>
<div class="panel admin-panel">
  <div class="panel-head"><strong><span class="icon-pencil-square-o"></span>
   学校设置</strong></div>
  <div class="body-content" >
    <form method="post" class="form-x" id="frm" action="">
    <div class="form-group">
        <div class="label">
          <label>学校全称：</label>
        </div>
        <div class="field">
          <input type="text" class="input" readonly name="swname" maxlength="100" value="{$Think.session.admin_info.schoolname}" />
          <div class="tips"></div>
        </div>
      </div>
      <div class="form-group">
        <div class="label">
          <label>学校简称：</label>
        </div>
        <div class="field">
          <input type="text" class="input" name="surl" maxlength="50" value="{$website.url}"/>
        </div>
      </div>
      <div class="form-group">
        <div class="label">
          <label>Logo：</label>
         </div>
        <div  class="field">
          <input type="button" class="button bg-blue " id="upload_btn0" value="+ 浏览上传"  style="float:left;">  
          <div id="single_pic0" class="single_pic">
            <if condition="$website['wlogo'] neq ''">
               <div class="item" id="file-0-{$website.id}">
                <input type="hidden" name="wlogo" value="{$website.wlogo}">
                  <img src="/{$website.wlogo}"  style="max-height:100px;   max-width:100px; " /> 
                  <div class="operate del" data-val="0-{$website.id}" > </div>
              </div>
           </if>
          </div>
            </div>
      </div>   
 
  <!--     <div class="form-group">

        <div class="label">
          <label>二维码：</label>
         </div>

        <div class="field">

           <input type="button" class="button bg-blue " id="upload_btn1" value="+ 浏览上传"  style="float:left;">  

          <div id="single_pic1" class="single_pic">

            <if condition="$website['wxlogo'] neq ''">
               <div class="item" id="file-1-{$website.id}">

                <input type="hidden" name="wxlogo" value="{$website.wxlogo}">

                  <img src="/{$website.wxlogo}"  style="max-height:100px;   max-width:100px; " /> 

                  <div class="operate del" data-val="1-{$website.id}" > </div>
              </div>
           </if>
          </div>
            </div>

      </div>   -->
      <div class="form-group">
        <div class="label">
          <label>学校简介：</label>
        </div>
        <div class="field">
          <textarea class="input" maxlength="1000" name="sdescription">{$website.description}</textarea>
          <div class="tips"></div>
        </div>
      </div>
      <div class="form-group">
        <div class="label">
          <label></label>
        </div>
        <div class="field">
         <input type="hidden" name="id" value="{$website.id}" >
          <input type="hidden" name="act" value="add" />
   <button class="button bg-main icon-check-square-o"  id="sbt"  type="button"> 提交</button>
        </div>
      </div>
    </form>
  </div>
</div>
<script type="text/javascript">
      $('.bg-blue').each(function(i,n){
        var uploader = new plupload.Uploader({
            browse_button:n.id,
            url: "{:U('Set/index')}",
            max_file_size: '2mb',
			multi_selection:false,//不允许多选
			prevent_duplicates: true ,//不允许选取重复文件
            filters: [{title: "Image files", extensions: "jpg,gif,png"}]
        });
        uploader.init();
	 	uploader.bind('FilesAdded',function(uploader,files){
		     var file_name = files[0].name; //文件名
			 var l_ength=$('#single_pic'+i).children('div.item').length;
		     if (l_ength>0) {
			    layer.msg('只能上传一张图片',{icon:2});
			    return;
           }
			 var html='<div class="item" id="file-' + files[0].id +'">  <div class="operate del" data-val="' + files[0].id +'" > </div> </div>';
			 $(html).appendTo('#single_pic'+i);
			!function(i){ 
			 previewImage(files[0],function(imgsrc){
			   var name=(i==0)?'wlogo':'wxlogo';		
		      $('#file-'+files[0].id).append('<input type="hidden"   name="'+name+'" value="' +imgsrc + '"><img src="'+ imgsrc +'" style="max-height:100px; max-width:100px;" />\n');
				})
			 }(i);
		 }); 
    uploader.bind('StateChanged', function(uploader) {
    if(uploader.files.length === (uploader.total.uploaded + uploader.total.failed))      {
           $('form')[0].submit();
       }
    });		

  //最后给"开始上传"按钮注册事件
    document.getElementById('sbt').onclick = function(){
        uploader.start();  
    }
  //删除图片
      $(document).on("click",".del", function() {
		   $(this).parent(".item").remove();
           var toremove = '';
           var id = $(this).attr("data-val");
           for (var i in uploader.files) {
             if (uploader.files[i].id === id) {
                   toremove = i;
                     }

               }
               uploader.files.splice(toremove, 1);
               })
  });	
	//plupload中为我们提供了mOxie对象
	//有关mOxie的介绍和说明请看：https://github.com/moxiecode/moxie/wiki/API
	//如果你不想了解那么多的话，那就照抄本示例的代码来得到预览的图片吧
	function previewImage(file,callback){
		//file为plupload事件监听函数参数中的file对象,callback为预览图片准备完成的回调函数
		if(!file || !/image\//.test(file.type)) return; //确保文件是图片
		if(file.type=='image/gif'){
			//gif使用FileReader进行预览,因为mOxie.Image只支持jpg和png
			var fr = new mOxie.FileReader();
			fr.onload = function(){
				callback(fr.result);
				//fr.destroy();
				fr = null;
			}
			fr.readAsDataURL(file.getSource());
		}else{
			var preloader = new mOxie.Image();
			preloader.onload = function() {
				preloader.downsize( 300, 300 );//先压缩一下要预览的图片,宽300，高300
				var imgsrc = preloader.type=='image/jpeg' ? preloader.getAsDataURL('image/jpeg',80) : preloader.getAsDataURL(); //得到图片src,实质为一个base64编码的数据
				callback && callback(imgsrc); //callback传入的参数为预览图片的url
				preloader.destroy();
				preloader = null;
			};
			preloader.load( file.getSource() );
		}	
	}
</script>

</body>

</html>